# coding:utf-8

import logging
import colorlog


class Log:
    def __init__(self, name=None, log_level=logging.INFO):
        """
        @param name: log name
        @log_level: log level
        """
        self.logger = logging.getLogger(name)

        self.logger.handlers = []

        self.logger.setLevel(log_level)

        console_fmt = '[%(asctime)s]-[%(name)s]-[line:%(lineno)d]-[%(levelname)s]: %(log_color)s%(message)s'

        color_config = {
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'purple',
        }

        console_formatter = colorlog.ColoredFormatter(fmt=console_fmt, log_colors=color_config)

        console_handler = logging.StreamHandler()

        console_handler.setFormatter(console_formatter)

        self.logger.addHandler(console_handler)

    def debug(self, message):
        self.logger.debug(message)

    def info(self, message):
        self.logger.info(message)

    def warning(self, message):
        self.logger.warning(message)

    def error(self, message):
        self.logger.error(message)

    def critical(self, message):
        self.logger.critical(message)
